package com.example.xd.phone_album

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import com.bumptech.glide.Glide
import kotlinx.android.synthetic.main.activity_detial.*

class DetialActivity : AppCompatActivity(), View.OnClickListener {
    var select_count: Int = 0
    var all_count: Int = 0
    var select: Boolean = false
    lateinit var singleImageModel: SingleImageModel
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_detial)
        singleImageModel = intent.getParcelableExtra<SingleImageModel>("file")
        select_count = intent.getIntExtra("select_size", 0)
        all_count = intent.getIntExtra("scan_size", 0)
        select = singleImageModel.isSelect
        setTvBg(select)
        Glide.with(this).load(singleImageModel.path).into(detial_big_img)
        detial_select_tv.setOnClickListener(this)
        detial_edit_tv.setOnClickListener(this)
        detial_tv_num.setOnClickListener(this)
        detial_select_num_tv.setOnClickListener(this)
    }

    private fun setTvBg(select: Boolean) {
        if (select) {
            detial_select_tv.setCompoundDrawablesWithIntrinsicBounds(
                getDrawable(R.drawable.circle_solid),
                null,
                null,
                null
            )
        } else {
            detial_select_tv.setCompoundDrawablesWithIntrinsicBounds(
                getDrawable(R.drawable.circle_empty),
                null,
                null,
                null
            )
        }
        detial_tv_num.setText(select_count.toString() + "/" + all_count)
        detial_select_num_tv.setText("完成" + select_count.toString() + "/9")
    }

    override fun onClick(v: View?) {
        when (v) {
            detial_select_tv -> {
                select = !select
                if (select) {
                    select_count++
                } else {
                    select_count--
                }
                setTvBg(select)
            }
            detial_edit_tv -> {
            }
            detial_tv_num -> {
                finish()
            }
            detial_select_num_tv -> {
                var intent = Intent()
                intent.putExtra("file", singleImageModel)
            }
        }
    }
}